package cn.com.suiyi.shixingshengxian.home.adapter;

import android.content.Context;

import android.content.Intent;
import android.view.View;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.com.suiyi.shixingshengxian.R;
import cn.com.suiyi.shixingshengxian.commoditydetail.CommodityActivity;
import cn.com.suiyi.shixingshengxian.home.bean.Vegetable;

/**
 * Created by hansen on 2016/7/19.
 */
public class VegetableAdapter extends RecyclerView.Adapter<VegetableAdapter.viewHold> {
    public List<Vegetable.DataBean.FloorItemBean> list;
    private Context context;
    public VegetableAdapter(Context context,List<Vegetable.DataBean.FloorItemBean> list){
        this.context=context;
        this.list=list;
    }

    @Override

    protected void convert(BaseViewHolder help, Vegetable.DataBean.FloorItemBean list) {
        help.setText(R.id.vegetable_vegeName,list.getProductName())
                .setText(R.id.vegetable_price,"￥"+list.getPRICE())
                .setText(R.id.vegetable_kg,"/"+list.getWeight());
        Glide.with(context).load(list.getImage()).into((ImageView) help.getView(R.id.vegetable_pic));

        help.setOnClickListener(R.id.vegetable_item, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context, CommodityActivity.class);
                context.startActivity(intent);
            }
        });

    public viewHold onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.fragemtn_vegetableitem,null);
        viewHold hold=new viewHold(view);

        return hold;
    }



    @Override
    public void onBindViewHolder(viewHold holder, int position) {
        holder.vegetable_vegeName.setText(list.get(position).getProductName());
        holder.vegetable_kg.setText(list.get(position).getWeight());
        holder.vegetable_price.setText((int) list.get(position).getPRICE());
        Glide.with(context).load(list.get(position).getImage()).into(holder.vegetable_pic);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class viewHold extends RecyclerView.ViewHolder {
        TextView vegetable_vegeName,vegetable_price,vegetable_kg;
                ImageView vegetable_pic;
        public viewHold(View itemView) {
            super(itemView);
            vegetable_vegeName= (TextView) itemView.findViewById(R.id.vegetable_vegeName);
            vegetable_price= (TextView) itemView.findViewById(R.id.vegetable_price);
            vegetable_kg= (TextView) itemView.findViewById(R.id.vegetable_kg);
            vegetable_pic= (ImageView) itemView.findViewById(R.id.vegetable_pic);

        }

    }


}
